﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Runtime.InteropServices;


namespace PlanB.SharePoint.UlsLogger
{


    /// <summary>
    /// 
    /// </summary>
    [Guid("833B687D-0DD1-4F17-BF6A-B64FBC1AC6A8")]
    public class SteveDiagnosticService : SPDiagnosticsServiceBase
    {
        private const string LOG_AREA = "Steve Area";

        public enum LogCategories
        {
            SteveCategory
        }

        public SteveDiagnosticService()
        {

        }

        public SteveDiagnosticService(string name, SPFarm parent)
            : base(name, parent)
        {

        }

        public static SteveDiagnosticService Local
        {
            get
            {
                return SPDiagnosticsServiceBase.GetLocal<SteveDiagnosticService>();
            }
        }


        public void LogMessage(ushort id, LogCategories LogCategory, TraceSeverity traceSeverity, string message, params object[] data)
        {
            if (traceSeverity != TraceSeverity.None)
            {
                SPDiagnosticsCategory category = Local.Areas[LOG_AREA].Categories[LogCategory.ToString()];
                Local.WriteTrace(id, category, traceSeverity, message, data);
            }
        }

        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
        {
            yield return new SPDiagnosticsArea(LOG_AREA, 0, 0, false,
                new List<SPDiagnosticsCategory>() { 
                    new SPDiagnosticsCategory("SampleCategory", TraceSeverity.Medium, EventSeverity.Information, 1, 0) 
                }
            );
        }

    }

}
